﻿#include "FITKAcousticsMaterialsFluid.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppSettings.h"
#include <QColor>

namespace Acoustics
{
    FITKAcousticsMaterialsFluid::FITKAcousticsMaterialsFluid()
    {
        this->updateDefaultColor();
    }

    FITKAcousticsAbsMaterial::AcousticsMaterialType FITKAcousticsMaterialsFluid::getAcousticsMaterialType()
    {
        return FITKAcousticsAbsMaterial::AcousticsMaterialType::Fluid;
    }

    double FITKAcousticsMaterialsFluid::getSpeedOfSound() const
    {
        return _speedOfSound;
    }

    void FITKAcousticsMaterialsFluid::setSpeedOfSound(double speedOfSound)
    {
        _speedOfSound = speedOfSound;
    }

    double FITKAcousticsMaterialsFluid::getKinematicViscosity() const
    {
        return _kinematicViscosity;
    }

    void FITKAcousticsMaterialsFluid::setKinematicViscosity(double kinematicViscosity)
    {
        _kinematicViscosity = kinematicViscosity;
    }

    double FITKAcousticsMaterialsFluid::getPrandtlNumber() const
    {
        return _prandtlNumber;
    }

    void FITKAcousticsMaterialsFluid::setPrandtlNumber(double prandtlNumber)
    {
        _prandtlNumber = prandtlNumber;
    }

    double FITKAcousticsMaterialsFluid::getSpecificHeatsRatio() const
    {
        return _specificHeatsRatio;
    }

    void FITKAcousticsMaterialsFluid::setSpecificHeatsRatio(double specificHeatsRatio)
    {
        _specificHeatsRatio = specificHeatsRatio;
    }

    double FITKAcousticsMaterialsFluid::getMolecularMass() const
    {
        return _molecularMass;
    }

    void FITKAcousticsMaterialsFluid::setMolecularMass(double molecularMass)
    {
        _molecularMass = molecularMass;
    }

    FITKAcousticsMaterialsFluid::FluidType FITKAcousticsMaterialsFluid::getType() const
    {
        return _type;
    }

    void FITKAcousticsMaterialsFluid::setType(const FluidType &type)
    {
        _type = type;
    }

    bool FITKAcousticsMaterialsFluid::copy(Core::FITKAbstractDataObject *obj)
    {
        //转换强制类型
        Acoustics::FITKAcousticsMaterialsFluid* data = dynamic_cast<Acoustics::FITKAcousticsMaterialsFluid*>(obj);

        if(nullptr == data)//判断是否转换成功
        {
            return false;
        }
        //复制成员变量
        _speedOfSound = data->getSpeedOfSound();
        _kinematicViscosity = data->getKinematicViscosity();
        _prandtlNumber = data->getPrandtlNumber();
        _specificHeatsRatio = data->getSpecificHeatsRatio();
        _molecularMass = data->getMolecularMass();
        _type = data->getType();

        // 调用父类的方法
        Acoustics::FITKAcousticsAbsMaterial::copy(obj);
        return true;
    }
    void FITKAcousticsMaterialsFluid::setColor(float r, float g, float b)
    {
        _color[0] = r;
        _color[1] = g;
        _color[2] = b;
    }

    void FITKAcousticsMaterialsFluid::getColor(float* rgb)
    {
        if (rgb == nullptr || _color == nullptr) return;

        for (int i = 0; i < 3; i++)
            rgb[i] = _color[i];
    }

    void FITKAcousticsMaterialsFluid::updateDefaultColor()
    {
        //获取软件设置
        AppFrame::FITKAppSettings* settings = FITKAPP->getAppSettings();
        if (!settings) return;
        //获取配置
        QVariant fluids = settings->getVarient("FluidsMaterialColor");
        //更新流体材料颜色
        if (fluids.isNull())
        {
            fluids = settings->getVarient("OriFluidsMaterialColor");
            if (fluids.isNull()) return;
        }
        QColor fluidsColor = fluids.value<QColor>();
        _color[0] = fluidsColor.redF();
        _color[1] = fluidsColor.greenF();
        _color[2] = fluidsColor.blueF();
    }
}
